export function updateNodeElement(el, vitrualDOM, oldVirtualDOM = {}) {
    const props = vitrualDOM.props || {}
    const oldProps = oldVirtualDOM.props || {}
    if (vitrualDOM.type === 'text') {
        if (props.textContent !== oldProps.textContent) {
            if (vitrualDOM.parent.type === oldVirtualDOM.parent.type) {
                vitrualDOM.parent.stateNode.replaceChild(document.createTextNode(props.textContent), oldVirtualDOM.stateNode)
            } else {
                vitrualDOM.parent.stateNode.appendChild(document.createTextNode(props.textContent))
            }
        }
        return
    }
    Object.keys(props).forEach(propName => {
        let val = props[propName]
        let oldVal = oldProps[propName]
        if (val !== oldVal) {
            // 事件处理
            if (propName.slice(0, 2) === 'on') {
                const eventName = propName.slice(2).toLowerCase()
                el.addEventListener(eventName, val)
                // 移除旧节点的事件

                if (oldVal) {
                    console.log(el.removeEventListener(eventName, oldVal))
                }
            } else if (propName === 'value' || propName === 'checked') {
                el[propName] = val
            } else if (propName !== 'children') {
                if (propName === 'className') {
                    el.setAttribute('class', val)
                } else {
                    // 其他属性 textContent
                    el.setAttribute(propName, val)
                }
            }
        }
    })
    // 删除老节点存在,新节点不存在的属性
    Object.keys(oldProps).forEach(oldPropName => {
        let val = props[oldPropName]
        const oldVal = oldProps[oldPropName]
        // 删除新节点中不存在的属性
        if (!val) {
            if (oldPropName.slice(0, 2) === 'on') {
                const eventName = propName.slice(2).toLowerCase()
                el.removeEventListener(eventName, oldVal)
            } else if (oldPropName === 'className') {
                el.removeAttribute('class')
            } else if (oldPropName !== 'children') {
                el.removeAttribute(oldPropName)
            }
        }
    })
}